//
//  TCNetworkTool.m
//  demo
//
//  Created by 王戈 on 15/6/10.
//  Copyright (c) 2015年 nice. All rights reserved.
//

#import "TCNetworkTool.h"
#import "PortHeader.h"
#import "AFNetworking.h"

@interface TCNetworkTool ()

@property (nonatomic, strong) AFHTTPRequestOperationManager *manager;

@end

@implementation TCNetworkTool

+ (TCNetworkTool *)sharedNetTool {
    static TCNetworkTool *_sharedNetTool = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _sharedNetTool = [[self alloc] init];
    });
    return _sharedNetTool;
}

- (AFHTTPRequestOperationManager *)manager {
    if (_manager == nil) {
        _manager = [AFHTTPRequestOperationManager manager];
        //申明返回的结果是json类型
        _manager.responseSerializer = [AFJSONResponseSerializer serializer];
        //申明请求的数据是json类型
        _manager.requestSerializer = [AFJSONRequestSerializer serializer];
        
        // 回头注释这句
        //        self.token = @"jXw-FLmHxEDBaePGza15nGmK3yN7kgaH5RONA91ssPVimxg52z9Ti_erysykK81Q3kGpmlWci9GwgKYB3CLuMSu13uyDpBspTYfrGJWFC0U2DVVLQnFbi3NsV3GJRly2TFUWb65mqN352MrKV2Dp4D-be4aGzSEq0x-TFVIadSurtnmYPWU5BBpbTT3XNDsERNGJ8_vLpXglco9mlF6FYky1c9Uu6gea3i1-6ooa52hyyzz2S8su8iCpJLYoB1DJaqzLv6Z9vNrrKCrQIKXm4dBFI-_WGolEdPdQaMY96xMf4BsFbXl69sPl6DwSyoK8WpXvmUT1_t1CZIaiXFZ4uEDK7B8GiZbBO5t0TWlVvWUVxxFAreeRgbrbqAN-L3icZSbJQsh1B-Sr6WvOckYYYOqF4lHmlUVnR6If1wCuzii-wcbrG_wJcgjRRayidmJADvwPVTKmptwQCAROfbBsmmclcSFACplVlCREEwbyUIk";
    }
    return _manager;
}

- (void)setToken:(NSString *)token {
    _token = token;
    if (self.manager) {
        [_manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",token] forHTTPHeaderField:@"Authorization"];
    }
}

#pragma mark - 注册
- (void)registerWithPhoneNum:(NSString *)phoneNum Email:(NSString *)email password:(NSString *)password confirmPassword:(NSString *)confirmPassword verifyCode:(NSString *)verifyCode CityId:(NSString *)CityId
            andSuccessBlocks:(NetDownLoadSuccessIdBlock)registerSuccess andFailureBlocks:(NetDownLoadFailureBlock)registerFailure {
    //传入的参数
    NSDictionary *parameters = @{@"UserName":phoneNum,
                                 @"Password":password,
                                 @"ConfirmPassword":confirmPassword,
                                 @"CityId":CityId,
                                 @"NickName":email,
                                 @"VerifyCode":verifyCode};
    //你的接口地址
    //发送请求
    [self.manager POST:REGISTER_URL parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            registerSuccess(responseObject);
        } else {
            registerSuccess(responseObject);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSDictionary *responseObject = operation.responseObject;
        if (responseObject[@"ModelState"]) {
            registerFailure([NSString stringWithFormat:@"%@",[responseObject[@"ModelState"] objectForKey:@""]]);
        } else if (responseObject[@"Message"]) {
            registerFailure(responseObject[@"Message"]);
        }
    }];
    
}

- (void)getUserinfoWithSuccessBlocks:(NetDownLoadSuccessIdBlock)getSuccess andFailureBlocks:(NetDownLoadFailureBlock)getFailure {
    
    [self.manager POST:GET_USERINFO parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            getSuccess(responseObject[@"Data"]);
        } else {
            getFailure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSHTTPURLResponse *response = [error.userInfo objectForKey:@"com.alamofire.serialization.response.error.response"];
        if ((long)response.statusCode == 401) {
            [[NSUserDefaults standardUserDefaults] setValue:@"NO" forKey:LOGIN_STATE];
            [[NSUserDefaults standardUserDefaults] synchronize];
            getFailure(@"401");
        }
        else
        {
            getFailure(@"获取用户信息失败 请重试 !");
        }
    }];
}

- (void)tokenWithEmail:(NSString *)email password:(NSString *)password andSuccessBlocks:(NetDownLoadSuccessIdBlock)registerSuccess andFailureBlocks:(NetDownLoadFailureBlock)registerFailure
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //申明返回的结果是json类型
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    
    NSDictionary *parameters = @{@"grant_type":@"password",
                                 @"username":email,
                                 @"password":password};
    
    NSString *url = @"http://api.51zjc.com/Token";
    //发送请求
    [manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        
        self.token = responseObject[@"access_token"];
        [[NSUserDefaults standardUserDefaults] setValue:self.token forKey:LOGIN_TOKEN];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [UserManager sharedUserManager].userModel.tokenDict = responseObject;
        [self getUserinfoWithSuccessBlocks:^(NSDictionary *successMessage) {
            [UserManager sharedUserManager].userModel.infoDict = successMessage;
            registerSuccess(nil);
        } andFailureBlocks:^(NSString *failureMessage) {
            registerFailure(@"获取用户信息失败 ,请稍后重试!");
        }];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSString *response = [operation.responseObject objectForKey:@"error_description"];
        registerFailure(response);
    }];
    
}

- (void)verifyCodeWithCallNumber:(NSString *)number andSuccessBlocks:(NetDownLoadSuccessBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure
{
    //传入的参数
    NSDictionary *parameters = @{@"Number":number};
    //你的接口地址
    //发送请求
    [self.manager POST:GetVerifyCode_URL parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            success([[responseObject  objectForKey:@"Data"] objectForKey:@"code"]);
        } else if ([responseObject[@"Successed"]  isEqual: @0]) {
            failure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure([NSString stringWithFormat:@"failed ! \noperation = %@ \n error = %@",operation,error]);
    }];
}

- (void)verifyCodeResetWithCallNumber:(NSString *)number andSuccessBlocks:(NetDownLoadSuccessBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure
{
    //传入的参数
    NSDictionary *parameters = @{@"cellphone":number};
    //你的接口地址
    //发送请求
    
    [self.manager GET:GetResetVerifyCode_URL(number) parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            success([[responseObject  objectForKey:@"Data"] objectForKey:@"code"]);
        } else if ([responseObject[@"Successed"]  isEqual: @0]) {
            failure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure([NSString stringWithFormat:@"failed ! \noperation = %@ \n error = %@",operation,error]);
    }];
}

- (void)areaWithParentID:(NSString *)parentID andSuccessBlocks:(NetDownLoadSuccessArrayBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //申明返回的结果是json类型
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    
    [manager GET:GetAllCityWithPid(parentID) parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            
            NSArray *array = operation.responseObject[@"Data"];
            NSMutableArray *areaArray = [NSMutableArray arrayWithCapacity:array.count];
            for (NSDictionary *dic in array) {
                AreaModel *area = [AreaModel areaModelWithDic:dic];
                [areaArray addObject:area];
            }
            success(areaArray);
        } else {
            failure(@"获取地区失败!");
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        TCLog(@"fail GetVerifyCode_URL operation %@",operation);
        TCLog(@"fail GetVerifyCode_URL error %@",error);
    }];
}


- (void)getCityIDWithLocation:(NSString *)location andSuccessBlocks:(NetDownLoadSuccessDicBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //申明返回的结果是json类型
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    NSDictionary *parameters = @{@"location": location};
    
    [manager GET:GET_CURRENTCITYID parameters:parameters success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            // 将url网址传回
            success([responseObject objectForKey:@"Data"]);
        } else {
            failure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure(@"获取当前城市失败，使用默认城市");
    }];
}

- (void)rentDetailWithID:(NSString *)ID andSuccessBlocks:(NetDownLoadSuccessDicBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure
{
    [self.manager.requestSerializer clearCityIdHeader];
    
    TCBaseTool *base = [TCBaseTool sharedBaseTool];
    
    [self.manager.requestSerializer setValue:base.currentCityId forHTTPHeaderField:@"CityId"];
    
    [self.manager POST:RentDetailWithID(ID) parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            success(responseObject[@"Data"]);
        } else {
            failure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure([NSString stringWithFormat:@"%@",error]);
    }];
}
// 调通
- (void)rentAddWithID:(NSString *)ID andTitle:(NSString *)title andPrice:(NSString *)price andArea:(NSString *)area andType:(NSString *)type andClostTo:(NSString *)closeTo andHistory:(NSString *)history andAddress:(NSString *)address andDescription:(NSString *)description andImageUrls:(NSArray *)ImageUrls andBrowseCount:(NSString *)browseCount andLatitude:(NSString *)Latitude andLongitude:(NSString *)Longitude andIsTop:(NSString *)IsTop andUserID:(NSString *)userID andCreatTime:(NSString *)createTime andState:(NSString *)State andAreaId:(NSString *)AreaId andCollectTimes:(NSString *)CollectTimes andLinkMan:(NSString *)linkMan andContractNum:(NSString *)contractNum SuccessBlocks:(NetDownLoadSuccessBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure {
    
    [self urlsWithImages:ImageUrls andSuccessBlock:^(NSArray *resultArray) {
        [SVProgressHUD showWithStatus:@"正在上传用户信息 请稍后.."];
        
        NSArray *urlArray = [resultArray copy];
        
        NSMutableDictionary *parameters =
        [NSMutableDictionary dictionaryWithDictionary:
         @{
           @"Title":title ? title : @"",
           @"Price" : price? price : @"",
           @"Area":area ? area : @"", // 面积
           @"Histroy": history ? history : @"",
           @"Address":address ? address : @"",
           @"Description":description ? description : @"",
           @"Type" : type ? type :@"",
           @"LinkMan" : linkMan ? :@"",
           @"ContactNumber" : contractNum ? : @""
           }];
        
        [parameters setValuesForKeysWithDictionary:[self urlDicFromURLArray:urlArray]];
        
        //发送请求
        [self.manager POST:RentAdd parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if ([responseObject[@"Successed"]  isEqual: @1]) {
                success(@"商铺添加成功!");
            } else {
                failure(responseObject[@"Message"]);
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSArray *arr = [[operation.responseObject objectForKey:@"ModelState"] objectForKey:@""];
            failure(arr.firstObject);
        }];
        
    } andFailureBlock:^(NSString *failureMessage) {
        failure(failureMessage);
    }];
    
}

- (void)getHomeAdvertiseSuccessBlocks:(NetDownLoadSuccessDicBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure
{
    //    [self.manager.requestSerializer clearCityIdHeader];
    TCBaseTool *base = [TCBaseTool sharedBaseTool];
    [self.manager.requestSerializer setValue:base.currentCityId forHTTPHeaderField:@"CityId"];
    
    //发送请求
    [self.manager GET:GET_HOMEINFO parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            success(responseObject[@"Data"]);
        } else {
            success(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure([NSString stringWithFormat:@"%@",error]);
    }];
}

- (void)getTailListWithPn:(NSString *)pn andDataType:(NSString *)type andCity:(NSString *)cityid SuccessBlocks:(NetDownLoadSuccessArrayBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure
{
    [self.manager.requestSerializer clearCityIdHeader];
    NSMutableDictionary *parameters = [[NSMutableDictionary alloc] initWithCapacity:5];
    TCBaseTool *base = [TCBaseTool sharedBaseTool];
    NSString *url;
    if (![cityid isEqualToString:@""] && cityid) {
        NSString *lati = [NSString stringWithFormat:@"%f",base.locaLatitude];
        NSString *longit = [NSString stringWithFormat:@"%f",base.locaLongitude];
        [self.manager.requestSerializer setValue:cityid forHTTPHeaderField:@"CityId"];
        [parameters setDictionary:@{@"pn":pn,@"latitude":@"0",@"longitude":@"0"}];
        url = [NSString stringWithFormat:@"%@?type=%@&latitude=%@&longitude=%@&pn=%@",POST_TAILINFO,type,@"0",@"0",pn];
    }
    else
    {
        [self.manager.requestSerializer setValue:base.currentCityId forHTTPHeaderField:@"CityId"];
        url = [NSString stringWithFormat:@"%@?type=%@&pn=%@",POST_TAILINFO,type,pn];
        [parameters setDictionary:@{@"pn":pn}];
    }
    
    //发送请求
    [self.manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            success(responseObject[@"Data"]);
        } else {
            success(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure([NSString stringWithFormat:@"获取数据失败，请下拉重试"]);
    }];
}

- (void)getJobListWithPn:(NSString *)pn andCity:(NSString *)cityid SuccessBlocks:(NetDownLoadSuccessArrayBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure
{
    [self.manager.requestSerializer clearCityIdHeader];
    NSMutableDictionary *parameters = [[NSMutableDictionary alloc] initWithCapacity:5];
    NSString *url;
    TCBaseTool *base = [TCBaseTool sharedBaseTool];
    if (![cityid isEqualToString:@""] && cityid) {
        NSString *lati = [NSString stringWithFormat:@"%f",base.locaLatitude];
        NSString *longit = [NSString stringWithFormat:@"%f",base.locaLongitude];
        if (base.currentCityId && base.currentCityId.length > 0)
        {
            [self.manager.requestSerializer setValue:base.currentCityId forHTTPHeaderField:@"CityId"];
        }
        [parameters setDictionary:@{@"pn":pn,@"latitude":lati,@"longitude":longit}];
        url = [NSString stringWithFormat:@"%@?latitude=%@&longitude=%@&pn=%@",POST_JOBINFO,lati,longit,pn];
    }
    else
    {
        if (base.currentCityId && base.currentCityId.length > 0)
        {
            [self.manager.requestSerializer setValue:base.currentCityId forHTTPHeaderField:@"CityId"];
        }
        url = [NSString stringWithFormat:@"%@?pn=%@",POST_JOBINFO,pn];
        [parameters setDictionary:@{@"pn":pn}];
    }
    
    //发送请求[NSString stringWithFormat:@"%@/%@",POST_TAILDETAIL,proId]latitude={latitude}&longitude={longitude}&pn={pn}
    [self.manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //        success([responseObject objectForKey:@"Data"]);
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            success(responseObject[@"Data"]);
        } else {
            success(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure([NSString stringWithFormat:@"获取数据失败，请下拉重试"]);
    }];
}

- (void)getMarketListWithPn:(NSString *)pn andCity:(NSString *)cityid SuccessBlocks:(NetDownLoadSuccessArrayBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure
{
    [self.manager.requestSerializer clearCityIdHeader];
    NSMutableDictionary *parameters = [[NSMutableDictionary alloc] initWithCapacity:5];
    NSString *url;
    TCBaseTool *base = [TCBaseTool sharedBaseTool];
    if (![cityid isEqualToString:@""] && cityid) {
        NSString *lati = [NSString stringWithFormat:@"%f",base.locaLatitude];
        NSString *longit = [NSString stringWithFormat:@"%f",base.locaLongitude];
        [self.manager.requestSerializer setValue:base.currentCityId forHTTPHeaderField:@"CityId"];
        [parameters setDictionary:@{@"pn":pn,@"latitude":lati,@"longitude":longit}];
        url = [NSString stringWithFormat:@"%@?latitude=%@&longitude=%@&pn=%@",POST_MARKETINFO,lati,longit,pn];
    }
    else
    {
        [self.manager.requestSerializer setValue:base.currentCityId forHTTPHeaderField:@"CityId"];
        [parameters setDictionary:@{@"pn":pn}];
        url = [NSString stringWithFormat:@"%@?pn=%@",POST_MARKETINFO,pn];
    }
    //发送请求
    [self.manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            NSArray *dicts = responseObject[@"Data"];
            NSMutableArray *outputArray = [NSMutableArray arrayWithCapacity:dicts.count];
            for (NSDictionary *dict in dicts) {
                MarketModel *market = [[MarketModel alloc] initWithDict:dict];
                [outputArray addObject:market];
            }
            success(outputArray);
        } else {
            failure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure(@"获取信息失败 ,请稍后重试!");
    }];
}

- (void)getShopListWithPn:(NSString *)pn andCity:(NSString *)cityid SuccessBlocks:(NetDownLoadSuccessArrayBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure
{
    [self.manager.requestSerializer clearCityIdHeader];
    NSMutableDictionary *parameters = [[NSMutableDictionary alloc] initWithCapacity:5];
    NSString *url;
    TCBaseTool *base = [TCBaseTool sharedBaseTool];
    if (![cityid isEqualToString:@""] && cityid) {
        NSString *lati = [NSString stringWithFormat:@"%f",base.locaLatitude];
        NSString *longit = [NSString stringWithFormat:@"%f",base.locaLongitude];
        [self.manager.requestSerializer setValue:base.currentCityId forHTTPHeaderField:@"CityId"];
        [parameters setDictionary:@{@"pn":pn,@"latitude":lati,@"longitude":longit}];
        url = [NSString stringWithFormat:@"%@?latitude=%@&longitude=%@&pn=%@",POST_SHOPINFO,lati,longit,pn];
    }
    else
    {
        [self.manager.requestSerializer setValue:base.currentCityId forHTTPHeaderField:@"CityId"];
        [parameters setDictionary:@{@"pn":pn}];
        url = [NSString stringWithFormat:@"%@?pn=%@",POST_SHOPINFO,pn];
    }
    //发送请求
    [self.manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            success(responseObject[@"Data"]);
        } else {
            success(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure([NSString stringWithFormat:@"获取数据失败，请下拉重试"]);
    }];
}

- (void)categoryListWithSuccessBlocks:(NetDownLoadSuccessArrayBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure {
    [self.manager.requestSerializer clearCityIdHeader];
    TCBaseTool *base = [TCBaseTool sharedBaseTool];
    [self.manager.requestSerializer setValue:base.currentCityId forHTTPHeaderField:@"CityId"];
    
    [self.manager POST:CategoryList parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            
            NSArray *dataArray = responseObject[@"Data"];
            NSMutableArray *returnArray = [NSMutableArray arrayWithCapacity:dataArray.count];
            for (NSDictionary *dataDic in dataArray) {
                CategoryModel *category = [[CategoryModel alloc] initWithDic:dataDic];
                [returnArray addObject:category];
            }
            success(returnArray);
        } else {
            failure(responseObject[@"Message"]);
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure(@"网络错误 ,请检查网络设置从新发送!");
    }];
}

- (void)categoryGetAllCompanyWithID:(NSString *)ID andSuccessBlocks:(NetDownLoadSuccessArrayBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure {
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    [manager.requestSerializer clearCityIdHeader];
    TCBaseTool *base = [TCBaseTool sharedBaseTool];
    [manager.requestSerializer setValue:base.currentCityId forHTTPHeaderField:@"CityId"];
    
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    [manager GET:CategoryGetAllCompanyWithID(ID) parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            
            NSArray *dataArray = responseObject[@"Data"];
            NSMutableArray *returnArray = [NSMutableArray arrayWithCapacity:dataArray.count];
            for (NSDictionary *dataDic in dataArray) {
                CompanyModel *company = [[CompanyModel alloc] initWithDic:dataDic];
                [returnArray addObject:company];
            }
            success(returnArray);
        } else {
            failure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        TCLog(@"%@",error);
    }];
}

- (void)getTailDetailInfoWithId:(NSString *)proId SuccessBlocks:(NetDownLoadSuccessDicBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure
{
    [self.manager.requestSerializer clearCityIdHeader];
    //    TCBaseTool *base = [TCBaseTool sharedBaseTool];
    //    [self.manager.requestSerializer setValue:base.currentCityId forHTTPHeaderField:@"CityId"];
    
    //发送请求
    [self.manager POST:[NSString stringWithFormat:@"%@/%@",POST_TAILDETAIL,proId] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            success(responseObject[@"Data"]);
        } else {
            success(responseObject[@"Message"]);
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure([NSString stringWithFormat:@"网络请求失败，请稍候再试！"]);
    }];
}


#pragma mark - 收藏相关

- (void)addFavouritesWithId:(NSString *)ID andUserId:(NSString *)userID andCollectType:(kTCCollectType)type andTypeID:(NSString *)typeID andAddTime:(NSString *)addTime andSuccessBlocks:(NetDownLoadSuccessBlock)addSuccess andFailureBlocks:(NetDownLoadFailureBlock)addFailure {
    
    [SVProgressHUD showWithStatus:@"正在提交数据 请稍后.."];
    
    NSDictionary *parameters = @{
                                 //                                 @"Id": ID ,
                                 //                                 @"UserId":userID ,
                                 @"Type" : [NSString stringWithFormat:@"%d",type],
                                 @"TypeId": typeID ,
                                 //                                 @"AddTime":addTime ,
                                 };
    [self.manager POST:FavouritesAdd parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            addSuccess(responseObject[@"Message"]);
            [MBHUDHelper showWarningWithText:responseObject[@"Message"]];
            [SVProgressHUD dismiss];
        } else {
            addFailure(responseObject[@"Message"]);
            [MBHUDHelper showWarningWithText:responseObject[@"Message"]];
            [SVProgressHUD dismiss];
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [SVProgressHUD dismiss];
        NSString *failureReason =  [operation.responseObject valueForKey:@"Message"];
        [MBHUDHelper showWarningWithText:(failureReason ? failureReason : @"操作失败 请稍后再试!")];
        [SVProgressHUD dismiss];
    }];
}

- (void)favouritetListWithPn:(NSString *)pn andSuccessBlocks:(NetDownLoadSuccessArrayBlock)querySuccess andFailureBlocks:(NetDownLoadFailureBlock)queryFailure {
    
    //发送请求
    [self.manager POST:FavouritesList(pn) parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            NSArray *array = responseObject[@"Data"];
            NSMutableArray *outputArray = [NSMutableArray arrayWithCapacity:array.count];
            for (NSDictionary *dic in array) {
                TCFavouriteModel *favour = [[TCFavouriteModel alloc] initWithDict:dic];
                [outputArray addObject:favour];
            }
            querySuccess(outputArray);
        } else {
            queryFailure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        queryFailure([NSString stringWithFormat:@"网络请求失败，请稍候再试！"]);
    }];
    
}

- (void)checkIsFavouritesWithType:(kTCCollectType)type andObjectID:(NSString *)objectID  andSuccessBlocks:(NetDownLoadSuccessBlock)checkSuccess andFailureBlocks:(NetDownLoadFailureBlock)checkFailure {
    
    NSDictionary *parameters = @{
                                 @"Type" : [NSString stringWithFormat:@"%d",type],
                                 @"TypeId": objectID
                                 };
    [self.manager POST:CheckIsFavourites parameters:parameters success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            checkSuccess(responseObject[@"Message"]); // 已关注此信息 or 未关注此信息
        } else {
            checkFailure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSString *failureReason =  [operation.responseObject valueForKey:@"Message"];
        checkFailure(failureReason ? failureReason : @"查询失败 请稍后再试!");
    }];
}

- (void)logoutWithSuccessBlocks:(NetDownLoadSuccessBlock)logoutSuccess andFailureBlocks:(NetDownLoadFailureBlock)logoutFailure {
    
    [self.manager POST:Logout parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //        if ([responseObject[@"Successed"]  isEqual: @1]) {
        logoutSuccess(responseObject[@"Message"]); // 已关注此信息 or 未关注此信息
        [[NSUserDefaults standardUserDefaults ] setValue:@"NO" forKey:LOGIN_STATE];
        [[NSUserDefaults standardUserDefaults ] setValue:@"" forKey:LOGIN_TOKEN];
        [[NSUserDefaults standardUserDefaults] synchronize];
        //        } else {
        //            logoutFailure(responseObject[@"Message"]);
        //        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        logoutFailure([NSString stringWithFormat:@"网络请求失败，请稍候再试！"]);
    }];
}

// Account/ChangePassword
- (void)changePasswordWithNewPD:(NSString *)newPassword andConfirmPassword:(NSString *)confirmPassword andOldPassword:(NSString *)oldPassword andSuccessBlocks:(NetDownLoadSuccessBlock)changeSuccess andFailureBlocks:(NetDownLoadFailureBlock)changeFailure {
    
    NSDictionary *parameters = @{
                                 @"NewPassword" : newPassword,
                                 @"ConfirmPassword" : confirmPassword,
                                 @"OldPassword" : oldPassword
                                 };
    [self.manager POST:ChangePassword parameters:parameters success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            changeSuccess(@"更改成功");
        } else {
            changeFailure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        changeFailure(@"更改失败,请稍后再试");
    }];
}

#pragma mark -重置密码
- (void)setPasswordWithCellPhone:(NSString *)phoneNum VerifyCode:(NSString *)verify NewPasswork:(NSString *)newPassword confirmPassword:(NSString *)confirmPassword andSuccessBlocks:(NetDownLoadSuccessBlock)setSuccess andFailureBlocks:(NetDownLoadFailureBlock)setFailure {
    
    NSDictionary *parameters = @{
                                 @"NewPassword":newPassword ,
                                 @"ConfirmPassword" : confirmPassword,
                                 @"VerifyCode" : verify,
                                 @"CellPhone" : phoneNum
                                 };
    
    
    //发送请求
    [self.manager POST:SET_PASSWORD_URL parameters:parameters success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            setSuccess(@"更改成功");
        } else {
            setFailure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        setFailure([NSString stringWithFormat:@"网络出错，请稍候再试!"]);
    }];
}

- (void)messageListWithPn:(NSString *)pn andSuccessBlocks:(NetDownLoadSuccessArrayBlock)querySuccess andFailureBlocks:(NetDownLoadFailureBlock)queryFailure {
    //发送请求
    [self.manager POST:GetMessageList(pn) parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            NSArray *tem = responseObject[@"Data"];
            NSMutableArray *outputArray = [NSMutableArray arrayWithCapacity:tem.count];
            for (NSDictionary *dic in tem) {
                MessageModel *message = [[MessageModel alloc] initWithDict:dic];
                [outputArray addObject:message];
            }
            querySuccess(outputArray);
            
        } else {
            queryFailure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        queryFailure([NSString stringWithFormat:@"网络失败，请稍候再试!"]);
    }];
}

- (void)userInfoEditWithHeadUrl:(NSString *)HeadUrl andNickName:(NSString *)NickName andSuccessBlocks:(NetDownLoadSuccessBlock)editSuccess andFailureBlocks:(NetDownLoadFailureBlock)editFailure {
    
    NSDictionary *parameters = @{
                                 @"NickName":NickName ,
                                 @"HeadUrl" : HeadUrl
                                 };
    
    
    //发送请求
    [self.manager POST:UserInfoEdit parameters:parameters success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            editSuccess(@"更改成功");
        } else {
            editFailure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        editFailure([NSString stringWithFormat:@"网络失败，请稍候再试!"]);
    }];
}

- (void)tailGoodsAddWithHeadImageUrls:(NSArray *)HeadImageUrls andBrand:(NSString *)Brand andStandard:(NSString *)Standard andCount:(NSString *)Count andPrice:(NSString *)Price andLinkMan:(NSString *)LinkMan andContactNumber:(NSString *)ContactNumber andCompanyAddress:(NSString *)CompanyAddress andType:(NSString *)Type andBrowseNumber:(NSString *)BrowseNumber andLatitude:(NSString *)Latitude andLongitude:(NSString *)Longitude andUserId:(NSString *)UserId andIsTop:(NSString *)IsTop andCreateTime:(NSString *)CreateTime andState:(NSString *)State andCollectTimes:(NSString *)CollectTimes andAreaId:(NSString *)AreaId andSuccessBlocks:(NetDownLoadSuccessBlock)addSuccess andFailureBlocks:(NetDownLoadFailureBlock)addFailure {
    
    if ([Type isEqualToString:@"求购"]) {
        Type = @"1";
    } else if ([Type isEqualToString:@"出售"]) {
        Type = @"0";
    } else {
        Type = @"2";
    }
    
    [self urlsWithImages:HeadImageUrls andSuccessBlock:^(NSArray *resultArray) {
       
        [SVProgressHUD showWithStatus:@"正在上传用户信息 请稍后.."];
        
        NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:
                                           @{
                                             @"Brand" : Brand,
                                             @"Standard": Standard ,
                                             @"Count" : Count,
                                             @"Price": Price ,
                                             @"LinkMan" : LinkMan,
                                             @"ContactNumber": ContactNumber ,
                                             @"CompanyAddress" : CompanyAddress,
                                             @"Type": Type
                                             }];
        [parameters setValuesForKeysWithDictionary:[self urlDicFromURLArray:resultArray]];
        
        //发送请求
        [self.manager POST:TailGoodsAdd parameters:parameters success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
            if ([responseObject[@"Successed"] isEqual: @1]) {
                addSuccess(@"上传成功");
            } else {
                NSString *failure = [responseObject valueForKey:@"Message"];
                addFailure(failure);
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            addFailure(@"添加失败 请稍后重试 !!");
        }];
        
    } andFailureBlock:^(NSString *failureMessage) {
        addFailure(failureMessage);
    }];
    
}

- (void)tailGoodsEditWithID:(NSString *)Id andHeadImageUrls:(NSArray *)HeadImageUrls andBrand:(NSString *)Brand andStandard:(NSString *)Standard andCount:(NSString *)Count andPrice:(NSString *)Price andLinkMan:(NSString *)LinkMan andContactNumber:(NSString *)ContactNumber andCompanyAddress:(NSString *)CompanyAddress andType:(NSString *)Type andBrowseNumber:(NSString *)BrowseNumber andLatitude:(NSString *)Latitude andLongitude:(NSString *)Longitude andUserId:(NSString *)UserId andIsTop:(NSString *)IsTop andCreateTime:(NSString *)CreateTime andState:(NSString *)State andCollectTimes:(NSString *)CollectTimes andAreaId:(NSString *)AreaId andSuccessBlocks:(NetDownLoadSuccessIdBlock)editSuccess andFailureBlocks:(NetDownLoadFailureBlock)editFailure {
    
    if ([Type isEqualToString:@"求购"] || [Type isEqualToString:@"1"]) {
        Type = @"1";
    } else if ([Type isEqualToString:@"出售"] || [Type isEqualToString:@"0"]) {
        Type = @"0";
    } else {
        Type = @"2";
    }
    
    [self urlsWithImages:HeadImageUrls andSuccessBlock:^(NSArray *resultArray) {
        
        [SVProgressHUD showWithStatus:@"正在上传用户信息 请稍后.."];
        
        NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:
                                           @{
                                             @"Id" : Id,
                                             @"Brand" : Brand,
                                             @"Standard": Standard ,
                                             @"Count" : Count,
                                             @"Price": Price ,
                                             @"LinkMan" : LinkMan,
                                             @"ContactNumber": ContactNumber ,
                                             @"CompanyAddress" : CompanyAddress,
                                             @"Type": Type
                                             }];
        [parameters setValuesForKeysWithDictionary:[self urlDicFromURLArray:resultArray]];
        
        //发送请求
        [self.manager POST:TailGoodsEdit parameters:parameters success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
            if ([responseObject[@"Successed"]  isEqual: @1]) {
                editSuccess(parameters);
            } else {
                editFailure(responseObject[@"Message"]);
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            editFailure(@"编辑失败 请稍后重试 !!");
        }];
        
    } andFailureBlock:^(NSString *failureMessage) {
        editFailure(failureMessage);
    }];
}

- (void)tailGoodsTopWithID:(NSString *)ID andSuccessBlocks:(NetDownLoadSuccessBlock)topSuccess andFailureBlocks:(NetDownLoadFailureBlock)topFailure {
    //发送请求
    [self.manager POST:TailGoodsTop(@"1") parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            topSuccess(@"置顶成功");
        } else {
            topFailure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        topFailure(@"置顶失败 请稍后重试 !!");
    }];
}

- (void)tailGoodsDeleteWithID:(NSString *)ID andSuccessBlocks:(NetDownLoadSuccessBlock)deleteSuccess andFailureBlocks:(NetDownLoadFailureBlock)deleteFailure {
    
    //发送请求
    [self.manager POST:TailGoodsDelete(ID) parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            deleteSuccess(@"删除成功");
        } else {
            deleteFailure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        deleteFailure(@"删除失败 请稍后重试 !!");
    }];
}

- (void)recruitmentAddWithId:(NSString *)Id andTitle:(NSString *)Title andWage:(NSString *)Wage andAddress:(NSString *)Address andPosition:(NSString *)Position andContactNumber:(NSString *)ContactNumber andRequirements:(NSString *)Requirements andCompanyName:(NSString *)CompanyName andCompanyScale:(NSString *)CompanyScale andCompanyFeature:(NSString *)CompanyFeature andLatitude:(NSString *)Latitude andLongitude:(NSString *)Longitude andState:(NSString *)State andCreateTime:(NSString *)CreateTime andIsTop:(NSString *)IsTop andUserId:(NSString *)UserId andBrowseNumber:(NSString *)BrowseNumber andCollectTimes:(NSString *)CollectTimes andAreaId:(NSString *)AreaId andWelfares:(NSDictionary *)Welfares andSuccessBlocks:(NetDownLoadSuccessBlock)addSuccess andFailureBlocks:(NetDownLoadFailureBlock)addFailure {
    
    NSDictionary *parameters = @{
                                 @"Title":Title ? Title : @"",
                                 @"Wage" : Wage ? Wage : @"",
                                 @"Address": Address ? Address : @"" ,
                                 @"Position" : Position ? Position : @"",
                                 @"ContactNumber": ContactNumber ? ContactNumber : @"" ,
                                 @"Requirements" : Requirements ? Requirements : @"",
                                 @"CompanyName": CompanyName ? CompanyName : @"" ,
                                 @"CompanyScale" : CompanyScale ? CompanyScale : @"",
                                 @"CompanyFeature": CompanyFeature ? CompanyFeature : @""
                                 };
    //发送请求
    [self.manager POST:RecruitmentAdd parameters:parameters success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"] isEqual: @1]) {
            addSuccess(@"添加成功 !");
        } else {
            NSString *failure = [responseObject valueForKey:@"Message"];
            addFailure(failure);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        addFailure(@"添加失败 请稍后重试 !!");
    }];
}

- (void)recruitmentEditWithId:(NSString *)Id andTitle:(NSString *)Title andWage:(NSString *)Wage andAddress:(NSString *)Address andPosition:(NSString *)Position andContactNumber:(NSString *)ContactNumber andRequirements:(NSString *)Requirements andCompanyName:(NSString *)CompanyName andCompanyScale:(NSString *)CompanyScale andCompanyFeature:(NSString *)CompanyFeature andLatitude:(NSString *)Latitude andLongitude:(NSString *)Longitude andState:(NSString *)State andCreateTime:(NSString *)CreateTime andIsTop:(NSString *)IsTop andUserId:(NSString *)UserId andBrowseNumber:(NSString *)BrowseNumber andCollectTimes:(NSString *)CollectTimes andAreaId:(NSString *)AreaId andWelfares:(NSDictionary *)Welfares andSuccessBlocks:(NetDownLoadSuccessIdBlock)editSuccess andFailureBlocks:(NetDownLoadFailureBlock)editFailure {
    
    NSDictionary *parameters = @{
                                 @"Id" : Id,
                                 @"Title":Title ? Title : @"",
                                 @"Wage" : Wage ? Wage : @"",
                                 @"Address": Address ? Address : @"" ,
                                 @"Position" : Position ? Position : @"",
                                 @"ContactNumber": ContactNumber ? ContactNumber : @"" ,
                                 @"Requirements" : Requirements ? Requirements : @"",
                                 @"CompanyName": CompanyName ? CompanyName : @"" ,
                                 @"CompanyScale" : CompanyScale ? CompanyScale : @"",
                                 @"CompanyFeature": CompanyFeature ? CompanyFeature : @""
                                 };
    
    
    //发送请求
    [self.manager POST:RecruitmentEdit parameters:parameters success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"] isEqual: @1]) {
            editSuccess(parameters);
        } else {
            NSString *failure = [responseObject valueForKey:@"Message"];
            editFailure(failure);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        editFailure(@"添加失败 请稍后重试 !!");
    }];
}

- (void)RecruitmentDeleteWithID:(NSString *)ID andSuccessBlocks:(NetDownLoadSuccessBlock)deleteSuccess andFailureBlocks:(NetDownLoadFailureBlock)deleteFailure {
    //发送请求
    [self.manager POST:RecruitmentDelete(ID) parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            deleteSuccess(@"删除成功");
        } else {
            deleteFailure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        deleteFailure(@"删除失败 请稍后重试 !!");
    }];
}

- (void)recruitmentTopWithID:(NSString *)ID andSuccessBlocks:(NetDownLoadSuccessBlock)topSuccess andFailureBlocks:(NetDownLoadFailureBlock)topFailure {
    //发送请求
    [self.manager POST:RecruitmentDetail(ID) parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            topSuccess(@"置顶成功");
        } else {
            topFailure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        topFailure(@"置顶失败 请稍后重试 !!");
    }];
}
// 调通
- (void)rentEditWithID:(NSString *)ID andTitle:(NSString *)title andPrice:(NSString *)price andArea:(NSString *)area andType:(NSString *)type andClostTo:(NSString *)closeTo andHistory:(NSString *)history andAddress:(NSString *)address andDescription:(NSString *)description andImageUrls:(NSArray *)ImageUrls andBrowseCount:(NSString *)browseCount andLatitude:(NSString *)Latitude andLongitude:(NSString *)Longitude andIsTop:(NSString *)IsTop andUserID:(NSString *)userID andCreatTime:(NSString *)createTime andState:(NSString *)State andAreaId:(NSString *)AreaId andCollectTimes:(NSString *)CollectTimes andLinkMan:(NSString *)linkMan andContractNum:(NSString *)contractNum SuccessBlocks:(NetDownLoadSuccessIdBlock)editSuccess andFailureBlocks:(NetDownLoadFailureBlock)editFailure {
    
    [self urlsWithImages:ImageUrls andSuccessBlock:^(NSArray *resultArray) {
        
        [SVProgressHUD showWithStatus:@"正在上传用户信息 请稍后.."];
        
        NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:
                                           @{
                                             @"Id" : ID,
                                             @"Title":title ? title : @"",
                                             @"Price" : price? price : @"",
                                             @"Area":area ? area : @"", // 面积
                                             @"Type":type ? type : @"" ,
                                             @"Histroy": history ? history : @"",
                                             @"Address":address ? address : @"",
                                             @"Description":description ? description : @"",
                                             @"LinkMan" : linkMan ? :@"",
                                             @"ContactNumber" : contractNum ? : @""
                                             }];
        
        [parameters setValuesForKeysWithDictionary:[self urlDicFromURLArray:resultArray]];
        
        [self.manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",self.token] forHTTPHeaderField:@"Authorization"];
        //发送请求
        [self.manager POST:RentEdit parameters:parameters success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
            if ([responseObject[@"Successed"]  isEqual: @1]) {
                editSuccess(parameters);
            } else {
                editFailure(responseObject[@"Message"]);
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            editFailure([NSString stringWithFormat:@"网络失败，请稍候再试！"]);
        }];
        
    } andFailureBlock:^(NSString *failureMessage) {
        editFailure(failureMessage);
    }];
}

// 调通
- (void)rentDeleteWithID:(NSString *)ID andSuccessBlocks:(NetDownLoadSuccessBlock)deleteSuccess andFailureBlocks:(NetDownLoadFailureBlock)deleteFailure {
    
    //发送请求
    [self.manager POST:RentDelete(ID) parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            deleteSuccess(@"删除成功");
        } else {
            deleteFailure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        deleteFailure(@"删除失败 请稍后重试 !!");
    }];
}
// 还不成
- (void)rentTopWithID:(NSString *)ID andSuccessBlocks:(NetDownLoadSuccessBlock)topSuccess andFailureBlocks:(NetDownLoadFailureBlock)topFailure
{
    [self.manager.requestSerializer setValue:[NSString stringWithFormat:@"Bearer %@",self.token] forHTTPHeaderField:@"Authorization"];
    //发送请求
    [self.manager POST:RentTop(ID) parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            topSuccess(@"置顶成功");
        } else {
            topFailure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        topFailure(@"置顶失败 请稍后重试 !!");
    }];
}
// 调通
- (void)MarketDetailWithID:(NSString *)ID andSuccessBlocks:(NetDownLoadSuccessIdBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure {
    //发送请求
    [self.manager POST:MarketDetail(ID) parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            MarketModel *market = [[MarketModel alloc] initWithDict:responseObject[@"Data"]];
            success(market);
        } else {
            failure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure(@"置顶失败 请稍后重试 !!");
    }];
}

- (void)GetCompanyWithID:(NSString * )ID andSuccessBlocks:(NetDownLoadSuccessArrayBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure {

    if (([ID isKindOfClass:[NSString class]] && [ID isEqualToString:@"0"]) && (ID >= 0) ) {
                failure(@"暂未开通企业");
                return;
    }
    //发送请求
    [self.manager GET:GetCompany(ID) parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            CompanyModel *company = [[CompanyModel alloc ]initWithDic:responseObject[@"Data"]];
            success(@[company]);
        } else {
            failure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure(@"获取失败 请稍后重试 !!");
    }];
}

// 调通
- (void)CompanyListWithBrand:(NSString *)brand andPN:(NSString *)pn andSuccessBlocks:(NetDownLoadSuccessArrayBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure {
    
    //发送请求
    [self.manager POST:CompanyListWithPNandBrand(pn, [brand stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]) parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            NSArray *dicts = responseObject[@"Data"];
            NSMutableArray *outputArray = [NSMutableArray arrayWithCapacity:dicts.count];
            for (NSDictionary *dict in dicts) {
                CompanyModel *market = [[CompanyModel alloc] initWithDic:dict];
                [outputArray addObject:market];
            }
            success(outputArray);
        } else {
            failure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure(@"置顶失败 请稍后重试 !!");
    }];
}

// 调通
- (void)PushCompanyListWithSuccessBlocks:(NetDownLoadSuccessArrayBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure {
    //发送请求
    [self.manager POST:PushCompanyList parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            NSArray *dicts = responseObject[@"Data"];
            NSMutableArray *outputArray = [NSMutableArray arrayWithCapacity:dicts.count];
            for (NSDictionary *dict in dicts) {
                CompanyModel *market = [[CompanyModel alloc] initWithDic:dict];
                [outputArray addObject:market];
            }
            success(outputArray);
        } else {
            failure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure(@"置顶失败 请稍后重试 !!");
    }];
}

- (void)RecruitmentDetailWithID:(NSString *)ID andSuccessBlocks:(NetDownLoadSuccessDicBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure {
    [self.manager POST:RecruitmentDetail(ID) parameters:nil success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            success([responseObject objectForKey:@"Data"]);
            
        } else {
            failure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

- (void)uploadImage:(UIImage *)image andSuccessBlocks:(NetDownLoadSuccessBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure {
    [self.manager POST:POST_UPLOADIMAGE parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        NSData *imageData = UIImageJPEGRepresentation(image, 0.4);
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat = @"yyyyMMddHHmmss";
        NSString *str = [formatter stringFromDate:[NSDate date]];
        NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str];
        
        // 上传图片，以文件流的格式
        [formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/jpeg"];
    } success:^(AFHTTPRequestOperation *operation, NSDictionary *responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            // 将url网址传回
            success([responseObject objectForKey:@"Data"]);
        } else {
            failure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure([error.userInfo objectForKey:@""]);
    }];
}

- (void)getShareInfoSuccessBlocks:(NetDownLoadSuccessBlock)success andFailureBlocks:(NetDownLoadFailureBlock)failure
{
    [self.manager GET:GET_SHARECONTENT parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if ([responseObject[@"Successed"]  isEqual: @1]) {
            success([responseObject objectForKey:@"Message"]);
        }
        else
        {
            failure(responseObject[@"Message"]);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        failure([error.userInfo objectForKey:@""]);
    }];
}

- (void)urlsWithImages :(NSArray *)images andSuccessBlock:(NetDownLoadSuccessArrayBlock)successBlock andFailureBlock:(NetDownLoadFailureBlock)failureBlock {
    
    __block NSInteger count = images.count;
    
    __block NSMutableArray *urlArrays = [NSMutableArray arrayWithCapacity:count];
    
    for (NSObject *ojb in images) {
        
        if ([ojb isKindOfClass:[NSString class]]) {
            [urlArrays addObject:ojb];
            count--;
        } else {
            [self uploadImage:(UIImage *)ojb andSuccessBlocks:^(NSString *successMessage) {
                [SVProgressHUD showWithStatus:[NSString stringWithFormat:@"正在上传第%lu张图片 请稍后..",(images.count - count)]];
                count--;
                [urlArrays addObject:successMessage];
                
                if (!count) {
                    successBlock([urlArrays copy]);
                }
            } andFailureBlocks:^(NSString *failureMessage) {
                failureBlock(failureMessage);
            }];
        }
    }
}


- (NSDictionary *)urlDicFromURLArray:(NSArray *)array {
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:6];
    for (int i = 0; i < array.count; i++) {
        NSString *url = array[i];
        
        switch (i) {
            case 0:
                [dic setValue:url forKey:@"img1"];
                break;
            case 1:
                [dic setValue:url forKey:@"img2"];
                break;
            case 2:
                [dic setValue:url forKey:@"img3"];
                break;
            case 3:
                [dic setValue:url forKey:@"img4"];
                break;
            case 4:
                [dic setValue:url forKey:@"img5"];
                break;
            case 5:
                [dic setValue:url forKey:@"img6"];
                break;
            default:
                break;
        }
    }
    return [dic copy];
}


@end
